#include "save_image.h"





SaveImage::SaveImage()
{

}


void SaveImage::addImage(string image_name , Mat image)
{
    pair<string,Mat> pair_obj;
    pair_obj.first = image_name;
    pair_obj.second= image;
    m_qDisplayFrameQueue.push_back(pair_obj);
}


void SaveImage::run()
{
    while (1)
    {

        pair<string,Mat> pai_obj;
        if (false == m_qDisplayFrameQueue.get(pai_obj))
        {
          QThread::msleep(10);
          continue;
        }
        imwrite(pai_obj.first,pai_obj.second);
    }
}


SaveImageThread::SaveImageThread()
{
    thread = new QThread(this);
    save_image  =  new SaveImage();
    save_image->moveToThread(thread);

    connect(this,&SaveImageThread::startThread,save_image,&SaveImage::run);
}

void SaveImageThread::run()
{
    thread->start();
    emit startThread();

}

void SaveImageThread::quit()
{
    thread->quit();
}

void SaveImageThread::addImage(string image_name , Mat image)
{
    save_image->addImage(image_name , image);
}
